export const schema = {
    type: "page",
    title: "团队项目列表",
    body: {
        type: "crud",
        api: "/api/project",
        filter: {
            title: "",
            panelClassName: 'm-b-none bg-gd no-border',
            bodyClassName: 'wrapper-sm',
            submitText: "",
            controls: [
                [
                    {
                        type: "select",
                        name: "team_id",
                        label: "项目查询",
                        placeholder: "团队名称",
                        clearable: true,
                        autoComplete: '/api/team/sug?term=${term}',
                        visibleOn: 'acl.can("team:create")'
                    },

                    {
                        type: "select",
                        name: "team_type",
                        label: "团队类型",
                        clearable: true,
                        source: "/api/setting/team_type"
                    },
                    {
                        type: "select",
                        name: "project_type",
                        label: "服务类型",
                        clearable: true,
                        source: "/api/setting/project_type"
                    }
                ],
                [
                    {
                        type: "select",
                        name: "progress",
                        label: "项目状态",
                        clearable: true,
                        options: [
                            {
                                label: '招募中',
                                value: '2'
                            },
                            {
                                label: '已招满',
                                value: '3'
                            },
                            {
                                label: '进行中',
                                value: '4'
                            },
                            {
                                label: '已结束',
                                value: '5'
                            }
                        ]
                    },

                    {
                        type: 'text',
                        name: 'name',
                        placeholder: '项目名称'
                    },

                    {
                        type: "submit",
                        label: "搜索",
                        primary: true
                    }
                ]
            ]
        },
        columns: [
            {
                name: "id",
                label: "项目ID",
                width: 50
            },
            {
                name: "name",
                label: "项目名称",
                type: "tpl",
                tpl: "<a data-link='/project/view/${id}'>${name}</a>"
            },
            {
                name: "name",
                label: "发起团队",
                type: "tpl",
                tpl: "<a data-link='/team/view/${team.id}'>${team.name}</a>"
            },
            {
                name: "project_type",
                label: "服务类型",
                innerClassName: 'word-break w-sm',
                type: 'tpl',
                tpl: '<% data.project_type && data.project_type.split(",").map(function(item) { %><span class="label label-info inline"><%= item %></span></span> <% }); %>'
            },

            {
                name: "service_target",
                label: "服务对象",
                type: 'tpl',
                innerClassName: 'word-break w-sm',
                tpl: '<% data.service_target && data.service_target.split(",").map(function(item) { %><span class="label label-info inline"><%= item %></span></span> <% }); %>'
            },

            {
                label: "地址",
                innerClassName: 'w project-address',
                // className: 'project-address',
                type: "tpl",
                tpl: "${province_name} ${city_name} ${county_name} ${addr}",
                // width: 200,
            },

            {
                label: "发起日期",
                name: "created_at",
                type: 'tpl',
                tpl: "${created_at|date:LL:YYYY-MM-DD HH:mm:ss}"
            },
            {
                label: "计划招募人数",
                name: 'people_count'
            },
            {
                label: "报名人数",
                name: 'apply_count'
            },
            {
                label: "录用人数",
                name: 'join_people_count'
            },
            {
                label: "项目状态",
                name: 'progress',
                type: 'map',
                map: {
                    '*': "${progress}",
                    '1': "<span class='label label-primary'>未开始</span>",
                    '2': "<span class='label label-info'>招募中</span>",
                    '3': "<span class='label label-info'>已满员</span>",
                    '4': "<span class='label label-success'>进行中</span>",
                    '5': "<span class='label label-default'>已结束</span>",
                    '255': "<span class='label label-default'>已下架</span>",
                }
            },

            {
                label: "操作",
                type: "operation",
                width: 180,
                visibleOn: "acl.can('project:create')",
                buttons: [
                    {
                        type: "button",
                        size: "xs",
                        label: "查看",
                        actionType: "dialog",
                        dialog: {
                            disabled: true,
                            title: "手机扫一扫查看页面",
                            size: 'sm',
                            body: `
                                <div class="text-center">
                                    <img src="/qrcode?size=250&data=<%= encodeURIComponent(data.preview_url) %>" />
                                </div>
                            `
                        }
                    },
                    {
                        type: "button",
                        size: "xs",
                        level: "info",
                        label: "编辑",
                        actionType: "link",
                        link: "/project/edit/${id}"
                    },

                    {
                        type: "button",
                        size: "xs",
                        level: "success",
                        label: "刷新",
                        actionType: 'ajax',
                        api: '/api/project/refresh/${id}'
                    },

                    {
                        type: "button",
                        size: "xs",
                        level: "primary",
                        label: "置顶",
                        actionType: 'ajax',
                        api: '/api/project/recommend/${id}',
                        visibleOn: 'acl.can("project:recommand") && !data.recommend_time'
                    },
                    {
                        type: "button",
                        size: "xs",
                        level: "warning",
                        label: "取消置顶",
                        actionType: 'ajax',
                        api: '/api/project/unRecommend/${id}',
                        visibleOn: 'acl.can("project:recommand") && data.recommend_time'
                    },
                    {
                        type: "button",
                        size: "xs",
                        level: "danger",
                        label: "下架",
                        actionType: 'ajax',
                        visibleOn: 'data.status == 1',
                        api: '/api/project/offline/${id}'
                    },
                    {
                        type: "button",
                        size: "xs",
                        level: "success",
                        label: "上架",
                        visibleOn: 'data.status == 0',
                        actionType: 'ajax',
                        api: '/api/project/online/${id}'
                    }
                ]
            }
        ]
    }
};
